﻿//using System;
//using System.Collections.Generic;

//namespace BO.Management
//{
//    /// <summary>
//    /// Provide methods to retrieve BO objects
//    /// </summary>
//    public class ObjectProvider : IDisposable
//    {

//        #region "Private members"
//        /// <summary>
//        /// BOE Query to search object by name 
//        /// </summary>
//        private const String _queryByName = "Select * From CI_SYSTEMOBJECTS WHERE SI_NAME = '{0}' AND SI_KIND ='{1}'";


//        /// <summary>
//        /// BOE Query to search object by Type 
//        /// </summary>
//        private const String _queryByType = "Select * From CI_INFOOBJECTS WHERE SI_KIND ='{0}'";

//        /// <summary>
//        /// BOE Query to search object by Id
//        /// </summary>
//        private const String _queryById = "Not yet implemented";

//        /// <summary>
//        /// Service provider is the internal class to retrieve BO services
//        /// </summary>
//        private ServiceProvider _serviceProvider;

//        /// <summary>
//        /// InfoStore is the persistent interface provided by BO to query in its database
//        /// </summary>
//        private CrystalDecisions.Enterprise.InfoStore _infoStore;

//        /// <summary>
//        /// A BOE opened session
//        /// </summary>
//        private CrystalDecisions.Enterprise.EnterpriseSession _session;

//        /// <summary>
//        /// the info store service from BO' services
//        /// </summary>
//        private CrystalDecisions.Enterprise.EnterpriseService _service;


//        private enum BOKInd
//        {
//            Server,
//            Event,
//            Folder,
//            Webi
//        }

//        #endregion

//        /// <summary>
//        /// Default constructor
//        /// </summary>
//        /// <param name="logonProvider">An active logonProvider with a opened session</param>
//        public ObjectProvider(LogonProvider logonProvider)
//        {
//            if (logonProvider == null || logonProvider.Session == null) throw new ArgumentNullException("BOE Session can't be null");
//            _session = logonProvider.Session;

//            _serviceProvider = new ServiceProvider(logonProvider);
//            _service = _serviceProvider.GetInfoStoreService();

//            _infoStore = new CrystalDecisions.Enterprise.InfoStore(_service);


//        }

//        /// <summary>
//        /// Get the persistent interface : InfoStore
//        /// Has to be disposed after its usage
//        /// </summary>
//        /// <param name="session"></param>
//        /// <returns></returns>
//        public CrystalDecisions.Enterprise.InfoStore GetNewInfoStore()
//        {
//            return new CrystalDecisions.Enterprise.InfoStore(_serviceProvider.GetInfoStoreService());
//        }


//        /// <summary>
//        /// Get a BOE server
//        /// </summary>
//        /// <param name="serverName"></param>
//        /// <returns></returns>
//        public CrystalDecisions.Enterprise.Desktop.Server GetServerByName(String serverName)
//        {

//            using (CrystalDecisions.Enterprise.InfoObjects result = _infoStore.Query(String.Format(_queryByName, serverName, BOKInd.Server)))
//            {
//                if (result != null && result.Count > 0)
//                {
//                    if (result.Count > 1) throw new Exception(String.Format("Expected 0 or one Server. Found {0} Server with this name", serverName));
//                    return (CrystalDecisions.Enterprise.Desktop.Server)result[1];
//                }
//                else
//                {
//                    return null;
//                }
//            }

//        }

//        /// <summary>
//        /// Get an Event by its name
//        /// </summary>
//        /// <param name="serverName"></param>
//        /// <returns></returns>
//        public CrystalDecisions.Enterprise.Desktop.Event GetEventByName(String eventName)
//        {

//            using (CrystalDecisions.Enterprise.InfoObjects result = _infoStore.Query(String.Format(_queryByName, eventName, BOKInd.Event)))
//            {
//                if (result != null && result.Count > 0)
//                {
//                    if (result.Count > 1) throw new Exception(String.Format("Expected 0 or one Event. Found {0} Event with this name", eventName));
//                    return (CrystalDecisions.Enterprise.Desktop.Event)result[1];
//                }
//                else
//                {
//                    return null;
//                }
//            }

//        }


//        public SortedList<String, CrystalDecisions.Enterprise.Desktop.Folder> GetFolders()
//        {
//            SortedList<String, CrystalDecisions.Enterprise.Desktop.Folder> folders = new SortedList<string, CrystalDecisions.Enterprise.Desktop.Folder>();

//            using (CrystalDecisions.Enterprise.InfoObjects result = _infoStore.Query(String.Format(_queryByType, BOKInd.Folder)))
//            {
//                if (result != null && result.Count > 0)
//                {
//                    for (int i = 1; i <= result.Count; i++)
//                    {
//                        CrystalDecisions.Enterprise.Desktop.Folder folder = (CrystalDecisions.Enterprise.Desktop.Folder)result[i];
//                        folders.Add(folder.CUID, folder);
//                    }
//                }
//            }

//            return folders;
//        }

//        public SortedList<String, BusinessObjects.Enterprise.Desktop.Webi> GetWebiReports()
//        {
//            SortedList<String, BusinessObjects.Enterprise.Desktop.Webi> reports = new SortedList<string, BusinessObjects.Enterprise.Desktop.Webi>();

//            using (CrystalDecisions.Enterprise.InfoObjects result = _infoStore.Query(String.Format(_queryByType, BOKInd.Webi)))
//            {
//                if (result != null && result.Count > 0)
//                {
//                    for (int i = 1; i <= result.Count; i++)
//                    {
//                        BusinessObjects.Enterprise.Desktop.Webi report = (BusinessObjects.Enterprise.Desktop.Webi)result[i];
//                        reports.Add(report.CUID, report);
//                    }
//                }
//            }

//            return reports;
//        }

//        public SortedList<String, CrystalDecisions.Enterprise.InfoObject> GetInfoObjects()
//        {
//            SortedList<String, CrystalDecisions.Enterprise.InfoObject> reports = new SortedList<string, CrystalDecisions.Enterprise.InfoObject>();

//            using (CrystalDecisions.Enterprise.InfoObjects result = _infoStore.Query(String.Format(_queryByType, BOKInd.Webi)))
//            {
//                if (result != null && result.Count > 0)
//                {
//                    for (int i = 1; i <= result.Count; i++)
//                    {
//                        CrystalDecisions.Enterprise.InfoObject report = result[i];
//                        reports.Add(report.CUID, report);
//                    }
//                }
//            }

//            return reports;
//        }

//        /// <summary>
//        /// Commit modification for an object
//        /// </summary>
//        /// <param name="objectBO"></param>
//        public void Commit(CrystalDecisions.Enterprise.InfoObject objectBO)
//        {
//            _infoStore.Commit(objectBO.ParentInfoObjects);
//        }





//        public void Dispose()
//        {
//            if (_infoStore != null) _infoStore.Dispose();
//        }
//    }
//}
